From 98b392699cbec92b75f1a5a0cfce2c51d5684922 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 10 Feb 2025 15:06:43 +0800 Subject: [PATCH] gui/macOS: Add convenience inline methods to check if VFS domain identifier is illegal or not Signed-off-by: Claudio Cambra --- src/gui/macOS/fileproviderdomainmanager_mac.mm | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/gui/macOS/fileproviderdomainmanager_mac.mm b/src/gui/macOS/fileproviderdomainmanager_mac.mm index b75c59bf7..d1660810a 100644 --- a/src/gui/macOS/fileproviderdomainmanager_mac.mm +++ b/src/gui/macOS/fileproviderdomainmanager_mac.mm @@ -43,6 +43,19 @@ static constexpr auto bundleExtensions = std::array{ QLatin1StringView(".saver"), QLatin1StringView(".mdimporter") }; +static const QRegularExpression illegalChars("[:/]"); + +inline bool hasBundleExtension(const QString &domainId) +{ + return std::any_of(bundleExtensions.begin(), bundleExtensions.end(), [&domainId](const auto &ext) { + return domainId.endsWith(ext); + }); +} + +inline bool illegalDomainIdentifier(const QString &domainId) +{ + return !domainId.isEmpty() && !illegalChars.match(domainId).hasMatch() && hasBundleExtension(domainId); +} QString domainIdentifierForAccount(const OCC::Account * const account) { @@ -50,7 +63,6 @@ QString domainIdentifierForAccount(const OCC::Account * const account) auto domainId = account->userIdAtHostWithPort(); Q_ASSERT(!domainId.isEmpty()); - static const QRegularExpression illegalChars("[:/]"); domainId.replace(illegalChars, "-"); // Some url domains like .app cause issues on macOS as these are also bundle extensions. -- 2.30.2